<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2019/5/5/005
 * Time: 14:36
 */

namespace app\Lib\Model\Img;


use app\Lib\Exception\BlException;

class DelFile
{
    private $imgId;
    public function __construct($imgId)
    {
        $this->imgId = $imgId;
    }

    /**
     * 删除文件方法
     * @return string
     * @throws BlException
     */
    public function run(){
        $img = new Img($this->imgId);
        $filePath =  $img->getFilePath();
        $model =  new \app\Lib\Model\DbModel\Img();
        $result =  $model->where([$model->_id=>$this->imgId])->delete();
        if(!$result){
            throw new BlException('删除失败');
        }
        $img->delAllCache();
        return $filePath;
    }
}